package cc.location.app;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationListener;

import cc.location.app.loc3.AMapLocationUtil;

public class MainActivity extends AppCompatActivity {

//    https://github.com/1143114725/EraJie/blob/544f8a9b73b9a4fb743d7b3fabc862110d56906a/app/src/main/java/com/erajiezhang/amap/location/AMapLocationUtil.java
//    https://github.com/18647499996/AndroidFrame
//    https://github.com/snpmyn/Amap/blob/master/location/build.gradle
//    https://github.com/0119zp/lib-Map/blob/master/lib_gaodelocation/src/main/java/com/zpan/gaodelocation/LocationLibManager.java
//    https://github.com/tianyalu/NeJetPakLifecycle/blob/18af7338c36bfe325a16772eb97f4410ecd87198/app/src/main/java/com/sty/ne/jetpaklifecycle/demo3/GPSEngine.java
//    https://github.com/Wayaer/fl_amap_map
//    https://github.com/teaphy/ArchsDemo/blob/ec82931bf6/archs/src/main/java/com/teaphy/archs/location/LocationHelper.kt
//    https://github.com/snpmyn/Widget
//    https://github.com/snpmyn/Util/blob/master/utilone/src/main/java/com/zsp/utilone/datetime/DateUtils.java
//    https://github.com/duanjisi/HDProject/blob/2161e0af49/app/src/main/java/com/atgc/hd/comm/local/GPSLocationTool.java
//    https://github.com/ChrisLeeLcx/CpLibrary/blob/863d98901b/app/src/main/java/com/lee/demo/util/gaode/loc/GaoDeLBSUtil.java
//    https://github.com/andych008/AMapDemo/blob/e2f94e8987/app/src/main/java/wang/unclecat/amapdemo/AMapLbs.java
//    https://github.com/andych008/AMapDemo/blob/e2f94e8987/app/src/main/java/wang/unclecat/amapdemo/MainActivity.java

//    https://github.com/DarrenWorks/base/blob/daf05e0228ce73f216787eb6e10ca86824388394/app/src/main/java/com/module/base/utils/AMapUtilKt.kt
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        location01();
        location02();
    }

    private void location02() {
        AMapLocationUtil.getInstance(this, new AMapLocationListener() {
            @Override
            public void onLocationChanged(AMapLocation aMapLocation) {
                //即使关闭定位也会有多次回调-也可以合理的地方stop  destroy适合销毁掉以后不用
                AMapLocationUtil.stopLocation();
//                LogUtils.i("定位成功:" + LocationUtils.getLocationLog(aMapLocation));
            }
        }).startOneClickLocation(null);
//        AMapLocationUtil.getInstance().startContinuedLocation();
//        AMapLocationUtil.getInstance().startOneClickLocation();
    }

    private void location01() {
        LocationManager.getInstance(this).setLocationListener(new LocationManager.OnLocationListener() {
            @Override
            public void onChange(AMapLocation aMapLocation) {
                if (aMapLocation.getErrorCode() == 0) {
                    //如果不关闭会多次调用，关闭是只调用一次
//                    LocationManager.stopLocation();
//                    LatLng currentLatLng = new LatLng(aMapLocation.getLatitude(), aMapLocation.getLongitude());
                    Log.i("shitou", "定位成功:" + LocationUtils.getLocationLog(aMapLocation));
                } else {
                    StringBuffer sb = new StringBuffer();
                    sb.append("定位失败" + "\n");
                    sb.append("错误码:" + aMapLocation.getErrorCode() + "\n");
                    sb.append("错误信息:" + aMapLocation.getErrorInfo() + "\n");
                    sb.append("错误描述:" + aMapLocation.getLocationDetail() + "\n");
                    Log.i("shitou", sb.toString());
                }
            }
        });
        LocationManager.startLocation();
    }
}